import request from "@/utils/request";
import {AxiosPromise} from "axios";
import {AgreementForm, AgreementQuery, SaveCondition} from "./types";
import {Result, TableDataInfo} from "@/model";


/**
 * 查询约起列表
 * @param params 条件
 * @returns 约起列表
 */
export function getAgreementList(params: AgreementQuery): AxiosPromise<TableDataInfo> {
    return request({
        url: "/admin/agreement/list",
        method: "get",
        params
    });
}

/**
 * 添加约起
 * @param data 约起信息
 */
export function addAgreement(data: AgreementForm): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/agreement/add",
        method: "post",
        data
    })
}

/**
 * 删除约起
 * @param data id和类别
 */
export function deleteAgreement(data: SaveCondition): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/agreement/delete",
        method: "delete",
        data
    })
}

/**
 * 修改约起
 * @param data 约起信息
 * @returns 修改结果
 */
export function updateAgreement(data: AgreementForm): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/agreement/update",
        method: "put",
        data,
    });
}

/**
 * 编辑约起
 * @param data id和类型
 * @returns 约起信息
 */
export function editAgreement(data: SaveCondition): AxiosPromise<Result<AgreementForm>> {
    return request({
        url: `/admin/agreement/edit`,
        method: "post",
        data
    });
}

/**
 * 上传约起图片
 * @returns 图片链接
 */
export function uploadAgreementImage(data: FormData): AxiosPromise<Result<string>> {
    return request({
        url: "/admin/agreementImage/upload",
        headers: {"content-type": "multipart/form-data"},
        method: "post",
        data,
    });
}
